package uk.co.foocode.sample.petclinic.web.util;

import java.util.Collection;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;

import uk.co.foocode.sample.petclinic.Clinic;
import uk.co.foocode.sample.petclinic.Owner;
import uk.co.foocode.sample.petclinic.Pet;
import uk.co.foocode.sample.petclinic.Vet;
import uk.co.foocode.sample.petclinic.Visit;
import uk.co.foocode.sample.petclinic.util.PagedListResults;

public class DwrClinic {
	
	
	private Logger logger = Logger.getLogger(DwrClinic.class);

	private Clinic clinic;
	public void setClinic(Clinic clinic) {
		this.clinic = clinic;
	}
	public Collection findVisits(Date startDate, Date endDate)
			throws DataAccessException {
		return clinic.findVisits(startDate, endDate);
	}
	public PagedListResults findVisitsPaged(Date startDate, Date endDate,Integer offset, Integer limit)
	throws DataAccessException {
		logger.info("findVisitsPaged("+startDate+", "+endDate+", "+offset+", "+limit+")");
		return clinic.findVisits(startDate, endDate,offset!=null?offset.intValue():0, limit!=null?limit.intValue():10);
	}
	
	public PagedListResults findVisitsPagedDefault(Date startDate, Date endDate,Integer offset, Integer limit)
	throws DataAccessException {
		logger.info("findVisitsPaged("+startDate+", "+endDate+", "+offset+", "+limit+")");
		Date sDate = startDate!=null?startDate:DateUtils.addYears(new Date(), -5);
		Date eDate = endDate!=null?endDate:DateUtils.addYears(new Date(), 5);
		return clinic.findVisits(sDate, eDate,offset!=null?offset.intValue():0, limit!=null?limit.intValue():10);
	}
	
	public Collection getPetTypes() throws DataAccessException {
		return clinic.getPetTypes();
	}
	public Collection getVets() throws DataAccessException {
		return clinic.getVets();
	}
	public Collection getPets() throws DataAccessException {
		return clinic.getPets();
	}
	public Owner loadOwner(int id) throws DataAccessException {
		return clinic.loadOwner(id);
	}
	public void storeVisit(Visit visit) throws DataAccessException {
		 clinic.storeVisit(visit);
	}
	public void storeOwner(Owner owner) throws DataAccessException {
		clinic.storeOwner(owner);
	}
	public void storePet(Pet pet) throws DataAccessException {
		clinic.storePet(pet);
	}
	public void storeVet(Vet vet) throws DataAccessException {
		clinic.storeVet(vet);
	}
	public Pet loadPet(int id) throws DataAccessException {
		return clinic.loadPet(id);
	}
	public Vet loadVet(int id) throws DataAccessException {
		return clinic.loadVet(id);
	}
	public Visit loadVisit(int id) throws DataAccessException {
		return clinic.loadVisit(id);
	}
	public Collection findOwners(String lastName) throws DataAccessException {
		return clinic.findOwners(lastName);
	}
	public Collection getSpecialties() throws DataAccessException {
		return clinic.getSpecialties();
	}
	
	
}
